package com.zkw.gro.cloure.demo

/**
 * Created by Administrator on 2016/4/9 0009.
 */

class SimpleDeclarationMain {

    /**
     * 闭包简单的声明方式
     * @return
     */
    def simpleDeclarationTest() {
        def log = ''
        (1..5).each { counter -> log += counter }
        assert log == '12345'

        def log1 = ''
        (1..5).each { log1 += it }
        assert log1 == '12345'


    }

    /**
     * 使用赋值的方式声明闭包1
     * @return
     */
    def declareClosure() {
        def printer = { line -> println 'ddd' + line }
        printer.call()
    }

    /**
     * 使用赋值的方式声明闭包2
     * @return
     */
    def Closure getPrinter() {
        def line = 2
        return { $line -> println line }
    }

    def

    public static void main(String[] args) {
        def simpleDeclarationMain = new SimpleDeclarationMain()
//        simpleDeclarationMain.simpleDeclarationTest()
//        simpleDeclarationMain.declareClosure()
//        Closure closure = simpleDeclarationMain.getPrinter()
//        closure.call()
//        Closure closure = simpleDeclarationMain.declareClosure()
//        closure.call()
    }
}
